home *** CD-ROM | disk | FTP | other *** search
- package icontrols;
-
- import com.ms.wd.core.Event;
- import com.ms.wd.ui.Control;
- import com.ms.wd.ui.Graphics;
- import com.ms.wd.ui.IButtonControl;
- import com.ms.wd.ui.Image;
- import com.ms.wd.ui.MouseEvent;
- import com.ms.wd.ui.PaintEvent;
- import com.ms.wd.ui.Point;
- import com.ms.wd.ui.Rectangle;
- import com.ms.wd.win32.Windows;
-
- public class HotButton extends Control implements IButtonControl {
- private boolean m_pressed = false;
- private boolean m_autoSize = false;
- private boolean m_radio = false;
- private boolean m_focus = false;
- private boolean m_stretch = false;
- private Image m_image = null;
- private Point m_imageSize = null;
- private boolean m_enabled = true;
- private ImageDisplayer m_displayer = new ImageDisplayer();
- private static final int CFOCUS = 3;
- private static final int CBORDER = 4;
-
- protected void onMouseEnter(Event e) {
- if (this.m_enabled) {
- this.m_focus = true;
- if (!this.m_radio && Control.getMouseButtons() != 0) {
- this.m_pressed = true;
- }
-
- ((Control)this).invalidate();
- }
- }
-
- protected void onLostFocus(Event e) {
- if (this.m_enabled) {
- this.m_focus = false;
- ((Control)this).invalidate();
- }
- }
-
- public void setRadio(boolean fRadio) {
- this.m_radio = fRadio;
- }
-
- public boolean getValue() {
- return this.m_pressed;
- }
-
- public boolean isEnabled() {
- return this.m_enabled;
- }
-
- public void setValue(boolean fValue) {
- this.m_pressed = fValue;
- ((Control)this).invalidate();
- }
-
- public boolean isRadio() {
- return this.m_radio;
- }
-
- public HotButton() {
- ((Control)this).setBounds(0, 0, 75, 25);
- ((Control)this).setTabStop(true);
- this.m_displayer.setAlignment(68);
- }
-
- public void onMouseUp(MouseEvent e) {
- if (this.m_enabled) {
- if (!this.m_radio) {
- this.m_pressed = false;
- } else {
- this.m_pressed = !this.m_pressed;
- }
-
- ((Control)this).invalidate();
- this.performClick();
- }
- }
-
- public void setStretch(boolean value) {
- if (value != this.m_stretch) {
- value = this.m_stretch;
- if (value) {
- this.m_displayer.setAlignment(Integer.MIN_VALUE);
- this.m_displayer.setStretch(true);
- } else {
- this.m_displayer.setAlignment(68);
- this.m_displayer.setStretch(false);
- }
-
- ((Control)this).invalidate();
- }
-
- }
-
- private void drawDottedRect(Graphics g, int x, int y, int width, int height, int dashLength) {
- for(int cx = x; cx < x + width; cx += dashLength * 2) {
- int cEnd = Math.min(x + width, cx + dashLength);
- g.drawLine(cx, y, cEnd, y);
- g.drawLine(cx, y + height, cEnd, y + height);
- }
-
- for(int cy = y; cy < y + height; cy += dashLength * 2) {
- int cEnd = Math.min(y + height, cy + dashLength);
- g.drawLine(x, cy, x, cEnd);
- g.drawLine(x + width, cy, x + width, cEnd);
- }
-
- }
-
- public boolean isStretch() {
- return this.m_stretch;
- }
-
- protected void onMouseLeave(Event e) {
- if (this.m_enabled) {
- this.m_focus = false;
- if (!this.m_radio) {
- this.m_pressed = false;
- ((Control)this).invalidate();
- }
-
- ((Control)this).invalidate();
- }
- }
-
- protected void onGotFocus(Event e) {
- if (this.m_enabled) {
- this.m_focus = true;
- ((Control)this).invalidate();
- }
- }
-
- protected void onMouseDown(MouseEvent e) {
- if (this.m_enabled) {
- if (!this.m_radio) {
- this.m_pressed = true;
- ((Control)this).invalidate();
- }
-
- super.onMouseDown(e);
- }
- }
-
- public Image getImage() {
- return this.m_image;
- }
-
- public boolean isAutoSize() {
- return this.m_autoSize;
- }
-
- protected void onResize(Event event) {
- ((Control)this).invalidate();
- }
-
- public void setAutoSize(boolean fAutoSize) {
- this.m_autoSize = fAutoSize;
- if (this.m_image != null) {
- this.setImage(this.m_image);
- }
-
- }
-
- public void performClick() {
- if (this.m_enabled) {
- ((Control)this).onClick(Event.EMPTY);
- }
-
- }
-
- protected void onPaint(PaintEvent pe) {
- Graphics g = pe.graphics;
- Rectangle bounds = ((Control)this).getClientRect();
- Rectangle innerBounds = new Rectangle(bounds.x + 2, bounds.y + 2, bounds.width - 4, bounds.height - 4);
- this.m_displayer.paintIn(g, innerBounds, pe.clipRect, this.m_image, this.m_imageSize);
- if (this.m_enabled) {
- if (this.m_focus && !this.m_pressed) {
- Windows.DrawEdge(g.getHandle(), bounds.toRECT(), 5, 15);
- } else if (this.m_pressed) {
- Windows.DrawEdge(g.getHandle(), bounds.toRECT(), 10, 15);
- }
- }
-
- super.onPaint(pe);
- }
-
- public void setImage(Image image) {
- this.m_image = image;
- this.m_imageSize = image.getSize();
- if (this.m_autoSize && image != null) {
- Point size = image.getSize();
- size.x += 8;
- size.y += 8;
- ((Control)this).setSize(size);
- }
-
- ((Control)this).invalidate();
- }
-
- public void setEnabled(boolean enabled) {
- if (enabled != this.m_enabled) {
- this.m_enabled = enabled;
- ((Control)this).invalidate();
- }
-
- }
-
- public void notifyDefault(boolean fDefault) {
- }
- }
-